*****USE DATA VERSION 11

keep if eligible==1
tsset cc_2 year,yearly

***GENERATE TIME DUMMIES
tab yearnum, gen(yrr)

***SELECT PRE-2004
gen samp2003=0
replace samp2003=1 if year<2004

****GENERATE TIME BY LEVEL 2 INTERACTIONS
gen yearnum203=yearnum*l203g
gen yearnum212=yearnum*l212g
gen yearnum221=yearnum*l221g
gen yearnum220=yearnum*l220g
gen yearnum222=yearnum*l222ig
gen yearnum225=yearnum*l225g
gen yearnum299=yearnum*l2999b
gen yearnum223=yearnum*l223g
gen yearnumtotaid=yearnum*l2999ag

****GENERATE AID BY LEVEL 1 INTERACTIONS
gen aidfpp=aid100g*fpp01g
gen aidfpp04=aid100g*fpp04g
gen aidgrowth=aid100g*prf01ig
gen aidfail=aid100g*pol25
gen aidviol=aid100g*pol05g
gen aidinfl=aid100g*prf02ig
gen aidunem=aid100g*soc07ig

****PER CAPITA TOTAL NON-DG AID, PRE-1990
gen l2999apc=l2999a/l220
gen yearnumapc=yearnum*l2999apc

****TOTAL AID STANDARDIZED BY GDP AND THEN BY YEARNUM
gen l2999gdp=l2999a/l227
gen yearnumgdp=yearnum*l2999gdp


***GENERATE TIME BY LEVEL 2 INTERACTION WITH TOTAL DG AND TOTAL NON-DG 1990-2004
gen yearnumtotdem=yearnum*l2100
gen yearnumtotndem=yearnum*l2000

***GENERATE GROUP-LEVEL MEANS FOR AID100 AND AID000

by cc_2, sort: egen aid100m=mean(aid100g)
by cc_2, sort: egen aid000m=mean(aid000g)

****GENERATE DUMMIES FOR DIFFERENT CUT POINTS ON AID100 FOR USE IN THRESHOLD MODELS
gen aid100cut=aid100g
recode aid100cut min=0 -2.524/-1.51=1 -1.509/1.357=2 1.3571/max=3
tab aid100cut, gen(aidcut)

****GENERATE FIXED COUNTRY DUMMIES

quietly tab cc_2, gen(cccc)


***GENERATE RUDRA MOMENTS
egen meanaid100g=mean(aid100g)
gen mom2=(aid100g-meanaid100g)^2
gen mom3=(aid100g-meanaid100g)^3

egen meanaid110=mean(aid110)
gen elmom2=(aid110-meanaid110)^2
gen elmom3=(aid110-meanaid110)^3

egen meanaid120=mean(aid120)
gen csmom2=(aid120-meanaid120)^2
gen csmom3=(aid120-meanaid120)^3

egen meanaid121=mean(aid121)
gen fpmom2=(aid121-meanaid121)^2
gen fpmom3=(aid121-meanaid121)^3

egen meanaid131=mean(aid131)
gen hrmom2=(aid131-meanaid131)^2
gen hrmom3=(aid131-meanaid131)^3

egen meanaid140=mean(aid140)
gen gvmom2=(aid140-meanaid140)^2
gen gvmom3=(aid140-meanaid140)^3



*************************************************
*****************************************************MODELS**********************************************************
*************************************************

*********FIXED EFFECTS WITH TIME DUMMIES -- TABLE 3.1
xtregar dg02i aid100g aid000g aid_2g rsaid1g rsaid0g oda100g oda000g prf01i fpp01 dif07 pol05 pol25 ///
yrr1-yrr12 if samp2003==1, fe

*********IV REG -- FIRST DIFFS TABLE 3.2
xtivreg2 dg02i yrr1-yrr12 aid000g aid_2g rsaid1g rsaid0g oda100g oda000g prf01ig fpp01g dif07g pol05g pol25 ///
(aid100g=l.fpp04 l.prf02i mom2 mom3) if samp2003==1, fd first


*********IV REG -- FIXED EFFECTS 
xtivreg2 dg02i yrr1-yrr12 aid000g aid_2g rsaid1g rsaid0g oda100g oda000g prf01ig fpp01g dif07g pol05g pol25 ///
(aid100g=l.fpp04 l.prf02i mom2 mom3) if samp2003==1, fe first


*****ARELLANO-BOND TABLE 3.3
xtabond dg02i aid000 aid_2 rsaid100 rsaid000 oda100 oda000 prf01i fpp01 dif07 pol05 pol25 ///
yrr2-yrr13 if samp2003==1, inst (fpp04 mom2 mom3 prf02i) pre(aid100, endogenous) small

xtabond dg02i aid000 aid_2 rsaid100 rsaid000 oda100 oda000 prf01i fpp01 dif07 pol05 pol25 ///
yrr2-yrr13 if samp2003==1, inst (fpp04 mom2 mom3 prf02i) pre(aid100, endogenous) robust small

